package vis.items.ds.stack;

import java.util.Observable;
import java.util.Observer;

import vis.app.controller.AppController;
import vis.app.controller.CodeController;
import vis.app.controller.EventControl;
import vis.items.visualItem.AbstractSketch;

public class StackSketch extends AbstractSketch implements Observer {

	private static final long serialVersionUID = 111649996972352901L;

	public StackSketch(String name) {
		super(name);
		System.out.println("Sketch Create: " + name);
	}

	@Override
	public void init() {
		super.init();
		System.out.printf("Sketch init! {w=%d,h=%d}", width, height);
	}

	private Stack stack;

	@Override
	public void setup() {
		super.setup();
		stack = new Stack(this, null);
	}

	@Override
	public void updateLogicInterval() {
		if (CodeController.getInstance().hasHighlightJobs()) {
			CodeController.getInstance().executeOneHighlightJob();
		}
	}

	@Override
	public void updateDataInOneFrame() {
		stack.update();
	}

	@Override
	public void drawFrame() {
		background(0x347C17);
		stack.display();
	}

	@Override
	public void update(Observable arg0, Object obj) {
		if (null == stack) {
			return;
		}

		EventControl eventCtr = (EventControl) obj;
		String actionType = eventCtr.actionControl;
		switch (actionType) {
		case AppController.ACTION_PUSH:
			stack.doPush();
			break;
		case AppController.ACTION_POP:
			stack.doPop();
			break;
		default:
			break;
		}
	}
}
